import java.util.Arrays;

public class test2 {
    //二分查找->必须是有序的数组
    public static int binarySearch(int[] array,int key){
        int left =0;
        int right =array.length-1;
        while(left<=right){
            int mid =(left+right)/2;
            if(array[mid]==key){
                return mid;
            }else if(array[mid]>key){
                right =mid-1;
            }else{
                left =mid+1;
            }
        }
        return -1;

    }
    public static void main(String[] args) {
        int[] array={1,2,31,4,16};
        System.out.println("排序前的数组:"+Arrays.toString(array));
        Arrays.sort(array);//默认从小到大排序
        System.out.println("排序后的数组:"+Arrays.toString(array));
        //int index = Arrays.binarySearch(array,1,3,16);
        int index = binarySearch(array,16);
        System.out.println(index);
    }
    public static void main6(String[] args) {
        int[] array1 = {1,2,3,4,5};
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;
        int[] array2 = new int[]{1,2,3,4,5};
        array2 [0] =100;
        array2[1] =200;
        array1 = array2;
        array2[2] =300;
        array2[3] =400;
        array2[4] = 500;
        for (int i=0;i<array1.length;i++){
            System.out.println(array1[i]);
        }
    }
    public static int[] func1(int[] array){
        //需求：把数组当中的每个数据 扩大2倍
        int[] ret = new int[array.length];
        for (int i=0;i<array.length;i++){
            ret[i] =array[i]*2;
        }
        return ret;
    }
    //需求：把数据当中的每个数据扩大2倍 -》 数组本身上扩大
    public static void func2(int[] array){
        for (int i=0;i<array.length;i++){
            array[i] = array[i]*2;
        }
    }
    public static void main5(String[] args) {
        int[] array1={1,2,3,4,5};
        func1(array1);
        System.out.println(Arrays.toString(array1));
        func2(array1);
        System.out.println(Arrays.toString(array1));

    }
    public static double max1(double a,double b){
        return a>b?a:b;
    }
    public static double max3(double a,double b,double c){
        int max = (int)max1(a,b);
        double ret = max1(max,c);
        return ret;
    }

    public static void main4(String[] args) {
        System.out.println(max3(1.5,2,4.5));
    }
    public static int add(int a,int b){
        return a+b;
    }
    public static float add(float a,float b,float c){
        return a+b+c;

    }
    public static void main3(String[] args) {
        System.out.println(max3(2,3,5));
        System.out.println(add(1,2,3));
        System.out.println(add(5,6));
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6};
        int[] array2 = new int[]{1,2,3,4,5,6};
        int[] array3 =new int[10];
        //int array4[] = {1,2,3,4,5}; 不建议
        int[] array4;
        array4 =new int[4];
        boolean[] flg= new boolean[3];
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        for (int i=0;i<array.length;i++){
            System.out.println(array[i]+" ");
        }
        System.out.println();
        System.out.println("=====");
        //for each 循环
        for(int x:array){
            System.out.println(x+" ");
        }
        System.out.println();
        System.out.println("=====");
        //操作数组的工具类 Arrays
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }
}
